<template>
    <div id="tmpl">
        <!--图片详情  -->
        <div id="desc">
            <div class="title">
                <h4>{{photoinfo.title}}</h4>
                <p>
                    {{photoinfo.add_time | datefmt("YYYY-MM-DD HH:mm:ss")}} &nbsp;&nbsp;{{photoinfo.click}}次点击
                </p>
                <p class="line"></p>
            </div>
            <!--缩略图  -->
            <div class="mui-content">
                <ul class="mui-table-view mui-grid-view mui-grid-9">
                    <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3" v-for="(item, index) in list">
                        <img class="preview-img"  :src="item.src" height="100" @click="$preview.open(index, list)">
                    </li>
                </ul>

            </div>
            <!--摘要  -->
            <p v-html="photoinfo.content"></p>
        </div>
        <!--评论  -->
        <div id="comment">
            <comment :id="id"></comment>
        </div>
    </div>
</template>
<script>
    import {
        Toast
    } from 'mint-ui';
    // 
    import comment from '../subcom/comment.vue'
    export default {
        components: {
            comment
        },
        data() {
            return {
                id: 0,
                //负责存储缩略图的数据
                list: [{
                    src: 'https://placekitten.com/600/400',
                    w: 600,
                    h: 400
                }, {
                    src: 'https://placekitten.com/1200/900',
                    w: 1200,
                    h: 900
                }],
                photoinfo: {}
            }
        },
        created() {
            this.id = this.$route.params.id;
            this.getinfo();
            this.getimg();
        },
        methods: {
            // 获取图片详细描述
            getinfo() {
                var url = 'http://182.254.146.100:8899/api/getimageInfo/' + this.id;
                this.$http.get(url).then(function (res) {
                    var body = res.body;
                    if (body.status != 0) {
                        Toast(body.message);
                        return;
                    }
                    // console.log(body);
                    this.photoinfo = body.message[0];
                })
            },
            getimg() {
                var url = 'http://182.254.146.100:8899/api/getthumimages/' + this.id;
                this.$http.get(url).then(function (res) {
                    var body = res.body;
                    console.log(body);
                    if (body.status != 0) {
                        Toast(body.message);
                        return;
                    }
                    body.message.forEach(function(item) {
                        //所有图片不管有多大都设置400*400 会呆滞图片失真 应该按照图片的实际大小设置
                        var img=document.createElement('img');
                        img.src=item.src;
                        item.h=img.height;
                        item.w=img.width;
                    });
                    this.list = body.message;
                })
            }
        }
    }
</script>
<style scoped>
    /*图片详情样式  */

    #desc {
        padding: 10px;
    }

    #desc h4 {
        color: #0094ff;
    }

    #desc .title p {
        color: rgba(0, 0, 0, .4);
        margin-top: 10px;
    }

    #desc .title .line {
        width: 100%;
        height: 1px;
        border-bottom: 1px solid rgba(0, 0, 0, .4)
    }

    .mui-content {
        background-color: #fff;
    }

    .mui-grid-view.mui-grid-9 {
        background-color: #fff;
    }

    .mui-grid-view.mui-grid-9 .mui-table-view-cell {
        border-right: 0px solid #eee;
        border-bottom: 0px solid #eee;
    }

    .mui-grid-view.mui-grid-9 {
        border-top: 0px solid #eee;
        border-left: 0px solid #eee;
    }

    .mui-content img {
        width: 100%;
    }
</style>